#include <GL/glut.h>

#include "cube.h"

Cube::Cube()
{
	_pos = Vec3f( 0.0f, 0.0f, 0.0f);
	_rot = Vec3f( 0.0f, 0.0f, 0.0f);
}

Cube::Cube(Vec3f p, Vec3f r)
{
	_pos = p;
	_rot = r;
}

void Cube::draw()
{
	// Draw four sides
	glPushMatrix();
	for (int i = 0; i < 4; i++)
	{
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		// Draw one face
		glBegin(GL_QUADS);
			glNormal3f( 0.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, 0.5f);
			glVertex3f( 0.5f, 0.5f, 0.5f);
			glVertex3f( 0.5f,-0.5f, 0.5f);
			glVertex3f(-0.5f,-0.5f, 0.5f);
		glEnd();
	}
	glPopMatrix();

	// Draw top and bottom
	glPushMatrix();
	glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
	glBegin(GL_QUADS);
		glNormal3f( 0.0f, 0.0f, 1.0f);
		glVertex3f(-0.5f, 0.5f, 0.5f);
		glVertex3f( 0.5f, 0.5f, 0.5f);
		glVertex3f( 0.5f,-0.5f, 0.5f);
		glVertex3f(-0.5f,-0.5f, 0.5f);
	glEnd();
	glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
	glBegin(GL_QUADS);
		glNormal3f( 0.0f, 0.0f, 1.0f);
		glVertex3f(-0.5f, 0.5f, 0.5f);
		glVertex3f( 0.5f, 0.5f, 0.5f);
		glVertex3f( 0.5f,-0.5f, 0.5f);
		glVertex3f(-0.5f,-0.5f, 0.5f);
	glEnd();
	glPopMatrix();
}

void Cube::act()
{
	_rot.y += 1.0f;
}

